/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import core.User;
import db.JDBC.JdbcDaoFactory;
import db.JDBC.UserJdbcDAO;
import javax.annotation.PostConstruct;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Anton
 */

public class UserSettingsBean
{
    private SessionBean sessionBean;
    private User user;
    private String newPassword;

    @PostConstruct
    public void init()
    {
        user = sessionBean.getCurrentUser();
    }

    public void updateUser(ActionEvent e)
    {
        UserJdbcDAO dao = JdbcDaoFactory.getInstance().getUserJdbcDAO();        
        if(user != null)
        {
            if(!newPassword.equals(""))
                user.setPassword(newPassword);
            System.out.println(user);
            dao.editUser(user);
        }
    }

    public void setUser(User user)
    {
        this.user = user;
    }
    public User getUser()
    {
        return user;
    }
    public String getNewPassword()
    {
            return newPassword;
    }
    public void setNewPassword(String newPassword)
    {
        this.newPassword = newPassword;
    }

    
    public SessionBean getSessionBean()
    {
        return sessionBean;
    }

    public void setSessionBean(SessionBean sessionBean)
    {
        this.sessionBean = sessionBean;
    }

}
